# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from typing import Union
from fastapi import Query
from pydantic import BaseModel, Field


class KnowSearchIn(BaseModel):
    """ 知识库搜索参数 """
    page_no: int = Query(default=1, gt=0, description="当前页码")
    page_size: int = Query(default=15, gt=0, le=200, description="每页条数")
    name: Union[str, None] = Query(default=None, description="知识库名称")
    user: Union[str, None] = Query(default=None, description="拥有者信息")


class KnowDetailIn(BaseModel):
    """ 知识库详情参数 """
    id: int = Query(..., gt=0, description="知识库ID")


class KnowPostIdIn(BaseModel):
    """ KnowID参数 """
    id: int = Field(gt=0, description="知识库ID", examples=[1])
    reason: str = Field(default="", max_length=65535, description="原因描述")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "reason": "原因说明"
            }
        }


"""--------------- Separator ---------------"""


class KnowWholeVo(BaseModel):
    """ 知识库全部VO """
    code: str = Field(description="编号")
    logo: str = Field(description="图标")
    name: str = Field(description="名称")
    vector_name: str = Field(description="模型名称")
    vector_model: str = Field(description="训练模型")
    is_disable: int = Field(description="是否禁用: [0=否, 1=是]")

    class Config:
        json_schema_extra = {
            "example": {
                "code": "wTS3mj23aj6kP",
                "logo": "https://www.xx.cn/logo.png",
                "name": "知识库名称",
                "vector_name": "OpenAI",
                "vector_model": "openai:text-embedding-ada-002"
            }
        }


class KnowListVo(BaseModel):
    """ 知识库列表Vo """
    class User(BaseModel):
        sn: str = Field(description="用户编号")
        mobile: str = Field(description="用户电话")
        nickname: str = Field(description="用户昵称")
        avatar: str = Field(description="用户头像")

    id: int = Field(description="知识库ID")
    code: str = Field(description="知识库编号")
    logo: str = Field(description="知识库图标")
    name: str = Field(description="知识库名称")
    vector_model: str = Field(description="向量模型")
    splits_model: str = Field(description="文件模型")
    train_total: int = Field(description="数据总量")
    is_disable: int = Field(description="是否禁用: [0=否, 1=是]")
    create_time: str = Field(description="创建时间")
    update_time: str = Field(description="更新时间")
    user: User = Field(description="拥有者")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "code": "dWKuXasRXpBbuCrm",
                "logo": "https://xx.com/static/images/default.png",
                "name": "法律宝典",
                "vector_model": "智谱清言",
                "splits_model": "智普清言:GLM-4-Long",
                "train_total": 0,
                "is_disable": 0,
                "create_time": "2025-05-08 09:57:12",
                "update_time": "2025-05-08 09:57:12",
                "user": {
                    "sn": "52778960",
                    "mobile": "13800138000",
                    "nickname": "罗非鱼",
                    "avatar": "http://127.0.0.1:8100/static/images/default_avatar.png"
                }
            }
        }


class KnowDetailVo(BaseModel):
    """ 知识库详情Vo """
    id: int = Field(description="知识库ID")
    code: str = Field(description="知识库编号")
    logo: str = Field(description="知识库图标")
    name: str = Field(description="知识库名称")
    intro: str = Field(description="知识库简介")
    vector_model: str = Field(description="向量模型")
    splits_model: str = Field(description="文件模型")
    is_disable: int = Field(description="是否禁用: [0=否, 1=是]")
    create_time: str = Field(description="创建时间")
    update_time: str = Field(description="更新时间")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "code": "dWKuXasRXpBbuCrm",
                "logo": "http://127.0.0.1:8100/static/images/default_robot.png",
                "name": "法律宝典",
                "intro": "这是简介",
                "vector_model": "zhipu:embedding-3",
                "splits_model": "zhipu:glm-4-long",
                "is_disable": 0,
                "create_time": "2025-05-08 09:57:12",
                "update_time": "2025-05-08 09:57:12"
            }
        }
